﻿using Microsoft.AspNetCore.Authorization;
using System;
using System.Linq;

namespace Common.Framework.Core.Common
{
    /// <summary>
    /// 
    /// </summary>
    [Authorize]
    public class AuthorizeBaseController : BaseController
    {
        /// <summary>
        /// 当前用户名
        /// </summary>
        protected long CurrentUserId
        {
            get
            {
                var userClaim = Request.HttpContext.User.Claims.FirstOrDefault(s => s.Type == "id");
                if (userClaim != null)
                {
                    return Convert.ToInt64(userClaim.Value);
                }
                return 0;
            }
        }
        /// <summary>
        /// 当前用户名
        /// </summary>
        protected string CurrentUserName
        {
            get
            {
                var userClaim = Request.HttpContext.User.Claims.FirstOrDefault(s => s.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier");
                if (userClaim != null)
                {
                    return userClaim.Value;
                }
                return "";
            }
        }
    }
}
